<?php
class Searchmodel extends Model {
	function Searchmodel() {
		parent::Model();
	}

	function search($severity) {
	}
	function search_coment($comments) {
	}
	function seach_pic($pc) {
	}
	function search_product($product) {
		$this->db->select('*');
		$this->db->from('user');
		$this->db->where('');
		$this->db->like('',$product);
		$this->db->order_by('','desc');
		return $this->db->get();
	}
	function search_ticket($ticket) {
		$this->db->select('a.*,b.*,c.*,d.*');
		$this->db->from('ticket a,product b,dept c,dept_detail d');
		$this->db->where('a.prod_id = b.prod_id and d.prod_id = b.prod_id and d.dept_id = c.dept_id ');
		$this->db->like('a.ticket_id',$ticket);
		$this->db->order_by('a.ticket_id','desc');
		
		return $this->db->get();
	}
	
	function search_dateRange($date) {
		$this->db->select('a.*,c.*');
		$this->db->from('ticket a,product c');
		$this->db->where('a.prod_id = c.prod_id ');
		$this->db->like('a.open_datetime',$date);
		$this->db->order_by('a.ticket_id','desc');
		
		return $this->db->get();
	}
	
	function search_severity($severity) {
		$this->db->select('a.*,c.*');
		$this->db->from('ticket a,product c');
		$this->db->where('a.prod_id = c.prod_id');
		$this->db->like('severity_level',$severity);
		
		return $this->db->get();
	}
	function search_comments($comments) {
		$this->db->select('a.*,b.*');
		$this->db->from('ticket a,comments b');
		$this->db->where('b.ticked_id = a.ticket_id');
		$this->db->like('b.comments',$comments);
		
		return $this->db->get();
	}
	
	function search_product2($product) {
		$this->db->select('*');
		$this->db->from('product');
		$this->db->like('product',$product);
		
		return $this->db->get();
	}
	
	function search_product23() {
		$this->db->select('*');
		$this->db->from('product');
		$this->db->order_by('prod_id','desc');
		
		return $this->db->get();
	}
	
	function search_tickets () {
		$this->db->select('*');
		$this->db->from('ticket');
		$this->db->order_by('ticket_id','desc');
		
		return $this->db->get();
	}
	
	function search_advanced($severity,$prod_id,$ticket_id,$date_time,$title) {
		/*$this->db->select('a.*,b.product,c.name');
		$this->db->from('ticket a,product b,user c');
		$this->db->where('a.prod_id = b.prod_id and a.user_id = c.user_id');
		
		$this->db->where('severity_level',$severity);
		$this->db->where('open_datetime',$date_time);
		$this->db->where('product',$prod_id);
		$this->db->where('ticket_id',$ticket_id);
		
		$this->db->like('title',$title);*/
		$query =mysql_query("select a.*,b.product,c.name from(ticket a,product b,user c) where a.prod_id = b.prod_id and a.user_id = c.user_id  and product ='$prod_id' and severity_level ='$severity' and (ticket_id like("%$ticket_id%") ||  open_datetime like("%$date_time%") || title like("%$title%"))");
		
		
		
		return $query;
	}
	function search_alls($id) {
		$this->data['title'] = 'Search All';
		$this->db->select('a.*,b.name,c.product');
		$this->db->from('ticket a,user b,product c');
		$this->db->where('a.user_id =b.user_id and a.prod_id =c.prod_id');
		$this->db->where('a.ticket_id',$id);
		
		return $this->db->get();
	}
}
?>